require 'resque/server'

Rails3BootstrapDeviseCancan::Application.routes.draw do

  # devise_for :users, :controllers => {:registrations => "registrations", :passwords => "passwords",
  #  :sessions => "sessions", :omniauth_callbacks => "users/omniauth_callbacks" }

  devise_scope :admin do
    devise_for :admins, controllers: {sessions: 'admin/sessions'}
  end

  resque_constraint = lambda do |request|
    request.env["warden"].authenticate? and request.env['warden'].user.admin?
  end
  constraints resque_constraint do
    mount Resque::Server, :at => "/resque"
  end

  resources :apps do
    member do
      post :watch
      post :connect
    end
  end

  resources :programs do
    collection do
      get :version
    end
  end

  resources :categories 
  resources :users
  resources :orders
  resources :terminals 
  resources :downloads

  mount API::Entrance => '/api'

  match '/update/:name', to: 'installations#update'
  
  match '/auth/:provider/callback', to: 'sessions#auth'
  match '/ymtv'  => 'ymtv#index'
  match '/get_apps' => 'home#get_apps'
  match '/help' => 'home#help'
  match '/about'  => 'home#about'
  match '/download'  => 'home#download'

  #match '/adv' => 'advertises#index'
  match '/finish' => 'advertises#finish' 

  match '/signin' => 'users#signin'

  resources :images do
    collection do
      get 'pull_image'
    end 
  end

  namespace :admin do
    get 'versions' => 'versions#index'
    get 'search' => 'dashboards#search'
    resources :app_connections
    resources :programs
    resources :watchings
    resources :terminal_versions
    resources :televisions
    resources :city_channels
    # resources :users
    # resources :orders
    resources :app_versions
    resources :downloads
    resources :account_signins
    resources :message_warnnings
    resources :terminal_orders do
      collection do
        get :export
        post :import
      end      
    end
    resources :terminal_versions
    resources :traffics do
      collection do
        get :search
        get :detail
        get :stat
      end
    end
    resources :areas
    resources :blacklists
    resources :wifi_accounts
    resources :wifi_logs
    resources :recommand_histories
    resources :terminal_groups
    resources :account_groups
    resources :accounts do
      collection do
        get :export
        post :import
      end
    end
    resources :api_visit_logs, only: [:index]
    resources :client_logs, only: [:index]
    resources :traffic_strategies do
      collection do
        get :enforce
      end
    end
    resources :terminals, :only => [:index, :show] do 
      member do
        post :remove
      end
      resources :terminal_infos
    end
    resources :recruitments, :controller=>"advertises"
    resources :tables, :only => [:index, :destroy]
    resources :permissions do
      collection do
        post :mass_update
      end
    end

    resources :creditcards
    resources :report_groups do
      collection do
        get :flow_report
        get :city_changed
        get :industry_changed
        get :group_name_changed
        get :tev
      end
    end

    resources :recommands, only: [:index]
    resources :recruitment_groups, :controller=>"advertise_groups" do
      member do
        get :rules
        post :update_rules
      end
    end

    resources :groups do
      member do
        post :add_permission
        post :delete_group_permission
      end
    end

    resources :admins do
      member do
        get :zone
        post :update_zone
        get :edit_password
        put :update_password
      end
    end

    resources :activities

    # get province list by country_id
    # get 'areas/get_provinces_by_country/:country_id' => 'areas#get_provinces_by_country', country_id: /\d+/
  end

  match '/admin' => 'admin/terminal_groups#index', as: :admin

  authenticated :user do
    root :to => 'home#index'
  end
  root :to => "home#index"
end
